﻿''' <summary>
''' 定数列属性
''' </summary>
''' <remarks></remarks>
<AttributeUsage(AttributeTargets.Property)>
Public Class StaticColumnAttribute
    Inherits ColumnAttribute

#Region "Constructor"
    Public Sub New()
        Me.LoadWhereCommandBuilder = AddressOf Me.CreateLoadWhereCommand

        Me.DirtyChecker = Function() False
        Me.InsertColumnCommandCreater = AddressOf Me.CreateSaveColumnCommand
        Me.IsUpdatable = False
    End Sub

    Public Sub New(ByVal ColumnName As String)
        Me.New()
        Me.ColumnName = ColumnName
    End Sub
#End Region

    Private _staticValue As String
    ''' <summary>
    ''' 定数
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Property StaticValue As String
        Get
            Return _staticValue
        End Get
        Set(value As String)
            _staticValue = value
        End Set
    End Property

    Private Sub CreateSaveColumnCommand(instance As Object, sqlColumnBuilder As System.Action(Of String), sqlValueBuilder As System.Action(Of String), paramRegister As System.Func(Of Object, Type, String))
        Me.SetValue(instance, Me.StaticValue)
        Me.DefaultInsertColumnCreater(instance, sqlColumnBuilder, sqlValueBuilder, paramRegister)
    End Sub

    Private Sub CreateLoadWhereCommand(value As Object, sqlBuilder As Action(Of String), paramRegister As Func(Of Object, String))
        Dim pname As String = paramRegister.Invoke(Me.StaticValue)
        sqlBuilder.Invoke(String.Format("{0} = {1}", Me.ColumnName, pname))
    End Sub

End Class
